package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.ToExamineInfo;

import com.tianhui.consignortwofei.pattern.orderStatus.status.IOrderStatus;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public class ToExamineListAdapter extends RecyclerArrayAdapter<ToExamineInfo> {
    private IOrderStatus iOrderStatus;
    private int rolePosition;
    private int which;

    public ToExamineListAdapter(Context context, IOrderStatus iOrderStatus,int rolePosition,int which) {
        super(context);
        this.iOrderStatus = iOrderStatus;
        this.rolePosition = rolePosition;
        this.which = which;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new InTransitListViewHolder(parent, R.layout.item_to_examine_list);
    }

    private class InTransitListViewHolder extends BaseViewHolder<ToExamineInfo> {


        private TextView tv_weight;
        private TextView tv_liulan;
        private TextView tv_zhuangtai;
        private TextView tv_zhuang_dress_one;
        private TextView tv_zhuang_dress_two;
        private TextView tv_zhuang_xie_one;
        private TextView tv_zhuang_xie_two;
        private LinearLayout ll_driver_line_body;
        private TextView tv_queren;
        private TextView tv_quxiao_queren;

        private TextView tv_guanli;
        private TextView tv_cancel;
        private TextView tv_name;
        private TextView tv_quxiao;

        private TextView  tv_shenhe_name;
        private TextView tv_xiashou_num;

        private TextView tv_bainji;
        private TextView tv_bainji_huozhu;
        private TextView tv_zhuan_yan;
        private TextView tv_weight_sheng;
        private TextView tv_huoquan;
//        private TextView tv_true_zhuang;





        public InTransitListViewHolder(ViewGroup parent, int res) {
            super(parent, res);


            tv_weight = getView(R.id.tv_weight);
            tv_liulan = getView(R.id.tv_liulan);
            tv_zhuangtai = getView(R.id.tv_zhuangtai);
            tv_zhuang_dress_one = getView(R.id.tv_zhuang_dress_one);
            tv_zhuang_dress_two = getView(R.id.tv_zhuang_dress_two);
            tv_zhuang_xie_one = getView(R.id.tv_zhuang_xie_one);
            tv_zhuang_xie_two = getView(R.id.tv_zhuang_xie_two);

            tv_queren = getView(R.id.tv_queren);
            tv_quxiao_queren = getView(R.id.tv_quxiao_queren);

            tv_guanli = getView(R.id.tv_guanli);
            tv_cancel = getView(R.id.tv_cancel);
            tv_name = getView(R.id.tv_name);
            tv_quxiao = getView(R.id.tv_quxiao);
            tv_shenhe_name = getView(R.id.tv_shenhe_name);
            tv_xiashou_num = getView(R.id.tv_xiashou_num);
            tv_bainji = getView(R.id.tv_bainji);
            tv_bainji_huozhu = getView(R.id.tv_bainji_huozhu);
            tv_zhuan_yan = getView(R.id.tv_zhuan_yan);
            tv_weight_sheng = getView(R.id.tv_weight_sheng);
            tv_huoquan = getView(R.id.tv_huoquan);

//            tv_true_shou = getView(R.id.tv_true_shou);
//            tv_true_zhuang = getView(R.id.tv_true_zhuang);



            addOnClickListener(R.id.tv_queren);
            addOnClickListener(R.id.tv_quxiao_queren);
            addOnClickListener(R.id.tv_liulan);
            addOnClickListener(R.id.tv_quxiao);
            addOnClickListener(R.id.tv_bainji);
            addOnClickListener(R.id.tv_bainji_huozhu);
            addOnClickListener(R.id.tv_zhuan_yan);
//            addOnClickListener(R.id.tv_true_zhuang);
        }

        @Override
        public void setData(ToExamineInfo data) {
            super.setData(data);

//            tv_name.setText(data.drivername);
//            tv_license.setText(data.vehiclenum);
            tv_zhuang_dress_one.setText(data.getDeliverprovince() + data.getDelivercity() + data.getDelivercounty() + data.getDeliverdetails());
            tv_zhuang_dress_two.setText(data.getDelivercity() + data.getDelivercounty());//+data.lendtime+"前"
            tv_zhuang_xie_one.setText(data.getDestinationprovince() + data.getDestinationcity() + data.getDestinationcounty() + data.getDestinationdetails());
            tv_zhuang_xie_two.setText(data.getDestinationcity() + data.getDestinationcounty());
            tv_weight.setText("总:"+data.getQuantity()+"吨");
            tv_huoquan.setText("货权:"+data.hq);

            tv_name.setText(data.destinationusername);
            tv_shenhe_name.setText(data.dispatcherusername);

            tv_liulan.setVisibility(View.GONE);
            //0 待审核、1已经审核 2退回,3作废
            if ("0".equals(data.status)){
                tv_zhuangtai.setTextColor(getContext().getResources().getColor(R.color.black));
                tv_zhuangtai.setText("待审核");
//                if (3==rolePosition){
//                    //2 销售，3物流
//                    tv_liulan.setVisibility(View.VISIBLE);
//                }
            }else if ("1".equals(data.status)){
                tv_zhuangtai.setTextColor(getContext().getResources().getColor(R.color.xui_btn_green_normal_color));
                tv_zhuangtai.setText("已经审核");
            }else if ("2".equals(data.status)){
                tv_zhuangtai.setText("退回");
                tv_zhuangtai.setTextColor(getContext().getResources().getColor(R.color.colorRed));
            }else {
                tv_zhuangtai.setText("作废");
                tv_zhuangtai.setTextColor(getContext().getResources().getColor(R.color.colorRed));
            }


            if (null!=data.code&&!TextUtils.isEmpty(data.code)){
                tv_xiashou_num.setVisibility(View.VISIBLE);
                tv_xiashou_num.setText("销售单号："+data.code);
            }else {
                tv_xiashou_num.setVisibility(View.GONE);
            }


            tv_bainji.setVisibility(View.GONE);
            tv_zhuan_yan.setVisibility(View.GONE);
            tv_bainji_huozhu.setVisibility(View.GONE);
            tv_queren.setVisibility(View.GONE);
            tv_quxiao_queren.setVisibility(View.GONE);
            tv_quxiao.setVisibility(View.GONE);
            switch (which){
                case 1://销售待审核
                    tv_bainji.setVisibility(View.VISIBLE);
                    tv_quxiao.setVisibility(View.VISIBLE);
                    break;
//                case 2:
//                    break;
                case 3:
                    tv_quxiao.setVisibility(View.VISIBLE);
                    break;
                case 4://物流待审核
                    tv_bainji_huozhu.setVisibility(View.VISIBLE);
                    tv_zhuan_yan.setVisibility(View.VISIBLE);
                    break;
//                case 5:
//                    break;
                case 6:
                    tv_quxiao.setVisibility(View.VISIBLE);
                    break;
                case 7:
                    tv_quxiao.setVisibility(View.GONE);
                    tv_queren.setVisibility(View.VISIBLE);
                    break;
                case 8:
                    tv_quxiao.setVisibility(View.GONE);
                    tv_quxiao_queren.setVisibility(View.VISIBLE);
                    break;
                case 99://都不显示
                    tv_quxiao.setVisibility(View.GONE);
                    break;

            }


            tv_weight_sheng.setVisibility(View.GONE);
            //重量
            if (null!=data.leftquantity&&!TextUtils.isEmpty(data.leftquantity)) {
                tv_weight_sheng.setText("剩余:"+data.leftquantity+"吨");
                tv_weight_sheng.setVisibility(View.VISIBLE);
            }


//            tv_yunfei.setText("￥"+data.totalprice);



//            int orderStatusType = iOrderStatus.getFeiOrderType();
//
//            if (OrderType.TYPE_CATCH_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.VISIBLE);
//                tv_cancel.setVisibility(View.VISIBLE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//            }else if (OrderType.TYPE_ING_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.VISIBLE);
//                tv_cancel.setVisibility(View.VISIBLE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//
//            }else if (OrderType.TYPE_PAYING_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.VISIBLE);
//                tv_cancel.setVisibility(View.GONE);
//                tv_true_shou.setVisibility(View.VISIBLE);
//                tv_true_zhuang.setVisibility(View.VISIBLE);
//
//            }else if (OrderType.TYPE_SUCCESS_TIME==orderStatusType){
//                tv_pay_type.setText("(已支付)");
//                tv_guanli.setVisibility(View.GONE);
//                tv_cancel.setVisibility(View.GONE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//
//            }else if (OrderType.TYPE_CANCEL_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.GONE);
//                tv_cancel.setVisibility(View.GONE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//
//            }




//                if (iOrderStatus.getOrderStatusType() == OrderType.TYPE_PAYMENT) {
//                    freightLinearLayout.setVisibility(View.VISIBLE);
//                    if (!TextUtils.isEmpty(data.issettle) && (data.issettle.equals("0") || data.issettle.equals("3"))) {
//                        submitTextView.setVisibility(View.VISIBLE);
//                    } else {
//                        submitTextView.setVisibility(View.GONE);
//                    }
//
//                } else {
//
//                }


//            //货源单号
//            orderNumberTextView.setText("货源单号：" + data.billno);
//            //取单地
//            twoDetailItemView.setContent(data.placeprovince + data.placecity + data.placecounty + data.placedetails);
//            //装货地
//            threeDetailItemView.setContent(data.deliverprovince + data.delivercity + data.delivercounty + data.deliverdetails);
//            //目的地
//            fourDetailItemView.setContent(data.destinationprovince + data.destinationcity + data.destinationcounty + data.destinationdetails);
//            //货权
//            if (RoleController.getInstance().isShowCustomerName()) {
//                sixDetailItemView.setVisibility(View.VISIBLE);
//                sixDetailItemView.setContent(data.customername);
//                sixDetailItemView.setTitle("货权：");
//            } else {
//                sixDetailItemView.setVisibility(View.GONE);
//            }
//            //车牌号
//            if (RoleController.getInstance().isDispatchOrderShowVehicleNumber()) {
//                eightDetailItemView.setVisibility(View.VISIBLE);
//                eightDetailItemView.setContent(data.vehiclenum);
//                eightDetailItemView.setTitle("车牌号：");
//            } else {
//                eightDetailItemView.setVisibility(View.GONE);
//            }


        }
    }
}
